// 扩展3.函数隐式类型转化
/**
* 之前学到std::string的时候就有个疑问，cstring方法可不可以传std::string参数。调的话，它会报错 error: invalid cast from type 'std::__cxx11::string' {aka 'std::__cxx11::basic_string<char>'} to type 'char*'  不存在从 "std::__cxx11::string" 到 "char *" 的适当转换函数C/C++
*/
#include <iostream>
class MyType
{
private:
  int i;
  char ch;

public:
  MyType(int, char);
  ~MyType();
  // MyType -> int 隐式类型转化
  operator int()
  {
    std::cout << "MyType -> int" << std::endl;
    return this->i;
  }
  operator char()
  {
    std::cout << "MyType -> char" << std::endl;
    return this->ch;
  }
};

MyType::MyType(int a, char b) : i(a), ch(b)
{
}

MyType::~MyType()
{
}

void print(int i, char ch)
{
  std::cout << " i : " << i << std::endl;
  std::cout << " ch : " << ch << std::endl;
}

int main(void)
{
  MyType mt(10, 'z');
  print(mt, mt);
  std::cout << (char)mt << std::endl;
  int i = mt;
  std::cout << i << std::endl;
  printf("-----------------end-----------------\n");
  return 0;
}